// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class iceMediator extends cc.Component {

    onLoad () {
        this.node.on("touchstart",this.touchStart,this);
        this.node.on("touchend",this.touchEnd,this);
        this.node.on("touchcancel",this.touchEnd,this);
    }

    touchStart(){
        this.schedule(this.iceScaleToSmall,0.5);
    }

    touchEnd(){
        this.unschedule(this.iceScaleToSmall);
    }

    iceScaleToSmall(){
        if(this.node.scale <= 0.3){
            this.node.destroy();
            this.unschedule(this.iceScaleToSmall);
            return;
        }
        cc.tween(this.node).by(0.2,{
            scale : -0.1
        }).start();
    }

}
